home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / GlueWindow4.1.2(source) Folder / Source(THINK C7.0) / GlueWindowCDEV4.1.2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-23  |  18.1 KB  |  697 lines  |  [TEXT/KAHL]

  1. //    GlueWindowCDEV4.1.2.c
  2.  
  3. //    inclusion of files -----------------------------
  4.  
  5. #include    <OSUtils.h>
  6. #include    "GlueWindow4.1.2.h"
  7.  
  8. //    definition -------------------------------------
  9.  
  10. enum    {    k_about    =    1,
  11.             k_drag_on,
  12.             k_grow_on,
  13.             k_push_on,
  14.             k_push_sound,
  15.             k_push_ctrl,
  16.             k_push_shift,
  17.             k_push_option,
  18.             k_push_command,
  19.             b_push_ctrl,
  20.             b_push_shift,
  21.             b_push_option,
  22.             b_push_command,
  23.             k_pop_on,
  24.             k_pop_sound,
  25.             k_pop_ctrl,
  26.             k_pop_shift,
  27.             k_pop_option,
  28.             k_pop_command,
  29.             b_pop_ctrl,
  30.             b_pop_shift,
  31.             b_pop_option,
  32.             b_pop_command,
  33.             k_show_icon,
  34.             k_no_marquee,
  35.             k_drag_ctrl,
  36.             k_drag_shift,
  37.             k_drag_option,
  38.             k_drag_command,
  39.             b_drag_ctrl,
  40.             b_drag_shift,
  41.             b_drag_option,
  42.             b_drag_command    };
  43.             
  44. #define        ALERT_RSRC        0
  45. #define        ABOUT_RSRC        1
  46. #define        RESTART_RSRC    2
  47. #define        SAME_RSRC        3
  48. #define        COMMAND_RSRC    4
  49. #define        NO_7_RSRC        5
  50. #define        WINDOW_ICON        2
  51. #define        key1            (**ch).temp_init_data.push_key
  52. #define        key2            (**ch).temp_init_data.pop_key
  53. #define        key3            (**ch).temp_init_data.drag_key
  54.  
  55. //    declaration of prototypes ----------------------
  56.  
  57. pascal long    main(short msg, short item, short numItems,
  58.                     short panelId, EventRecord *evntp, long val,
  59.                         DialogPtr dp);
  60. Boolean    is_system7(void);
  61. Handle    Get1Resource_in_system_heap(OSType rType, short id);
  62.                     
  63. short        NumToolboxTraps( void );
  64. TrapType    GetTrapType(short theTrap);
  65. Boolean        TrapAvailable(short theTrap);
  66.  
  67. long            do_check(DialogPtr dp);
  68. long            do_init    (DialogPtr dp, short numItems);
  69. init_data_hdl    load_setting(void);
  70. int                open_prefs_file(prefs_file *pf);
  71. void            save_setting(init_data_hdl save_data_hdl, prefs_file *pf_ptr);
  72. void            do_close(cdev_data_hdl ch);
  73.  
  74. void do_hit            (cdev_data_hdl ch, DialogPtr dp, short hit_item,
  75.                                 EventRecord *evntp, short numItems);
  76. void apply_setting    (cdev_data_hdl cur_data_hdl);
  77. void setup_ditems    (cdev_data_hdl ch, DialogPtr dp, short numItems);
  78. void hilite_btn        (cdev_data_hdl ch, DialogPtr dp, short numItems);
  79. void set_check_btn    (DialogPtr dp, short item_num, Boolean check);
  80. void check_key_combination(cdev_data_hdl ch, short key_num);
  81. void about(short id, void *p);
  82.  
  83. //    main routines ----------------------------------
  84.  
  85. pascal long main(short msg, short item, short numItems, short panelId,
  86.                     EventRecord *evntp, long val, DialogPtr dp)
  87. {
  88.     long    rv;
  89.     
  90.     rv = val;
  91.     switch(msg) {
  92.         case nulDev:
  93.         case activDev:
  94.         case deactivDev:
  95.         case keyEvtDev:
  96.         case undoDev:
  97.         case cutDev:
  98.         case copyDev:
  99.         case pasteDev:
  100.         case clearDev:
  101.         case updateDev:
  102.             break;
  103.         case macDev:
  104.             rv = do_check(dp);
  105.             break;
  106.         case initDev:
  107.             rv = do_init(dp, numItems);
  108.             break;
  109.         case closeDev:
  110.             do_close((cdev_data_hdl)val);
  111.             break;
  112.         case hitDev:
  113.             do_hit((cdev_data_hdl)val, dp, item + numItems, evntp, numItems);
  114.             break;
  115.     }
  116.     return(rv);
  117. }
  118.  
  119. Boolean is_system7(void)
  120. {
  121.     Boolean    f;
  122.     OSErr    err;
  123.     long    r;
  124.     
  125.     if(f = TrapAvailable(_Gestalt)) {
  126.         err = Gestalt(gestaltSystemVersion, &r);
  127.         if(err != noErr)    f = false;
  128.         else if(r <0x0700) f = false;
  129.         else f = true;
  130.     }
  131.     return(f);
  132. }
  133.  
  134. Handle Get1Resource_in_system_heap(OSType rType, short id)
  135. {
  136.     THz        oldZone;
  137.     Handle    h;
  138.     
  139.     oldZone = GetZone();
  140.     SetZone(SystemZone());
  141.     h = Get1Resource(rType, id);
  142.     SetZone(oldZone);
  143.     return(h);
  144. }
  145.  
  146. //    gestalt check routines -------------------------
  147.  
  148. #define TrapMask 0x0800
  149.  
  150. short NumToolboxTraps( void )
  151. {
  152.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  153.             NGetTrapAddress(0xAA6E, ToolTrap))
  154.         return(0x0200);
  155.     else
  156.         return(0x0400);
  157. }
  158.  
  159. TrapType GetTrapType(short theTrap)
  160. {
  161.  
  162.     if ((theTrap & TrapMask) > 0)
  163.         return(ToolTrap);
  164.     else
  165.         return(OSTrap);
  166.  
  167. }
  168.  
  169. Boolean TrapAvailable(short theTrap)
  170. {
  171.  
  172.     TrapType    tType;
  173.  
  174.     tType = GetTrapType(theTrap);
  175.     if (tType == ToolTrap)
  176.     theTrap = theTrap & 0x07FF;
  177.     if (theTrap >= NumToolboxTraps())
  178.         theTrap = _Unimplemented;
  179.  
  180.     return (NGetTrapAddress(theTrap, tType) !=
  181.             NGetTrapAddress(_Unimplemented, ToolTrap));
  182. }
  183.  
  184. //    event routines ---------------------------------
  185.  
  186.     //    open and close routines ------------------------
  187.  
  188. long do_check(DialogPtr dp)
  189. {
  190.     Handle        h;
  191.     long        is_ok = 0, address;
  192.     int            er;
  193.     OSErr        err;
  194.     prefs_file    pf;
  195.     
  196.     SetPort(dp);
  197.     if( TrapAvailable(_Gestalt) ) {
  198.         if(is_system7()) {
  199.             er = open_prefs_file(&pf);
  200.             if(er == NO_ERROR) {
  201.                 is_ok = 2;
  202.                 h = Get1Resource(SETTING_RSRC, RSRC_NUMBER_BASE + 1);
  203.                 if(h) {
  204.                     err = Gestalt(CREATOR, &address);
  205.                     if(err == NO_ERROR)
  206.                         is_ok = 1;
  207.                 }
  208.                 CloseResFile(CurResFile());
  209.             }
  210.                 //    When you receive macDev message, you should check
  211.                 //    your control panel can run. If it can, return 1.
  212.                 //    If cannot, return 0.
  213.         }
  214.     }
  215.     if(is_ok == 0)
  216.         Alert(RSRC_NUMBER_BASE + NO_7_RSRC, nil);
  217.     if(is_ok == 2) {
  218.         Alert(RSRC_NUMBER_BASE + RESTART_RSRC, nil);
  219.         is_ok = 0;
  220.     }
  221.         
  222.     return(is_ok);
  223. }
  224.  
  225. long do_init(DialogPtr dp, short numItems)
  226. {
  227.     cdev_data_hdl    ch;
  228.     init_data_hdl    ih;
  229.     Handle            h;
  230.     
  231.     SetPort(dp);
  232.     ih = load_setting();
  233.     if(!ih)        Alert(RSRC_NUMBER_BASE + ALERT_RSRC, nil);
  234.     ch = (cdev_data_hdl)NewHandle(sizeof(cdev_data));
  235.     (**ch).temp_init_data = **ih;
  236.     DisposeHandle((Handle)ih);
  237.     setup_ditems(ch , dp, numItems);
  238.     return((long)ch);
  239. }
  240.  
  241. init_data_hdl load_setting(void)
  242. {
  243.     init_data_hdl        h = nil, sysheap_data_hdl = nil;
  244.     old_init_data_hdl    old_h = nil;
  245.     short                save_ref_num;
  246.     prefs_file            pf;
  247.     int                    er;
  248.     OSErr                err;
  249.     long                address;
  250.  
  251.     err = Gestalt(CREATOR, &address);
  252.     
  253.     if(err == NO_ERROR) {
  254.         h = (init_data_hdl)NewHandle(sizeof(init_data));
  255.         sysheap_data_hdl = (init_data_hdl)address;
  256.         **h = **sysheap_data_hdl;
  257.     }
  258.     else {
  259.         save_ref_num = CurResFile();
  260.         er = open_prefs_file(&pf);
  261.         if(er != CAUTION_ERROR) {
  262.             if(er == NO_ERROR) {
  263.                 h = (init_data_hdl)Get1Resource_in_system_heap(SETTING_RSRC, RSRC_NUMBER_BASE + 1);
  264.                 if(h) {
  265.                     HNoPurge((Handle)h);
  266.                     DetachResource((Handle)h);
  267.                 }
  268.                 else {
  269.                     old_h = (old_init_data_hdl)Get1Resource(SETTING_RSRC, RSRC_NUMBER_BASE);
  270.                     if(old_h) {
  271.                         h = (init_data_hdl)NewHandleSys(sizeof(init_data));
  272.                         if(h) {
  273.                             (**h).drag_on        = (**(init_data_hdl)old_h).drag_on;
  274.                             (**h).grow_on        = (**(init_data_hdl)old_h).grow_on;
  275.                             (**h).push_on        = (**(init_data_hdl)old_h).push_on;
  276.                             (**h).pop_on        = (**(init_data_hdl)old_h).pop_on;
  277.                             (**h).push_sound    = (**(init_data_hdl)old_h).push_sound;
  278.                             (**h).pop_sound        = (**(init_data_hdl)old_h).pop_sound;
  279.                             (**h).push_key[0]    = (**(init_data_hdl)old_h).push_key[0];
  280.                             (**h).push_key[1]    = (**(init_data_hdl)old_h).push_key[1];
  281.                             (**h).push_key[2]    = (**(init_data_hdl)old_h).push_key[2];
  282.                             (**h).push_key[3]    = (**(init_data_hdl)old_h).push_key[3];
  283.                             (**h).pop_key[0]    = (**(init_data_hdl)old_h).pop_key[0];
  284.                             (**h).pop_key[1]    = (**(init_data_hdl)old_h).pop_key[1];
  285.                             (**h).pop_key[2]    = (**(init_data_hdl)old_h).pop_key[2];
  286.                             (**h).pop_key[3]    = (**(init_data_hdl)old_h).pop_key[3];
  287.                             (**h).show_init_icon= (**(init_data_hdl)old_h).show_init_icon;
  288.                             (**h).no_marquee    = false;
  289.                             (**h).drag_key[0]    = false;
  290.                             (**h).drag_key[1]    = false;
  291.                             (**h).drag_key[2]    = false;
  292.                             (**h).drag_key[3]    = true;
  293.                             ReleaseResource((Handle)old_h);
  294.                             save_setting(h, &pf);
  295.                         }
  296.                     }
  297.                 }
  298.                 CloseResFile(pf.RsrcRefNum);
  299.             }
  300.             else if(er == OPEN_ERROR) {
  301.                 h = (init_data_hdl)NewHandleSys(sizeof(init_data));
  302.                 if(h) {
  303.                     (**h).drag_on        = true;
  304.                     (**h).grow_on        = true;
  305.                     (**h).push_on        = true;
  306.                     (**h).pop_on        = true;
  307.                     (**h).push_sound    = true;
  308.                     (**h).pop_sound        = true;
  309.                     (**h).push_key[0]    = false;
  310.                     (**h).push_key[1]    = true;
  311.                     (**h).push_key[2]    = false;
  312.                     (**h).push_key[3]    = false;
  313.                     (**h).pop_key[0]    = true;
  314.                     (**h).pop_key[1]    = false;
  315.                     (**h).pop_key[2]    = false;
  316.                     (**h).pop_key[3]    = false;
  317.                     (**h).show_init_icon= true;
  318.                     (**h).no_marquee    = false;
  319.                     (**h).drag_key[0]    = false;
  320.                     (**h).drag_key[1]    = false;
  321.                     (**h).drag_key[2]    = false;
  322.                     (**h).drag_key[3]    = true;
  323.                     save_setting(h, &pf);
  324.                 }
  325.             }
  326.             UseResFile(save_ref_num);
  327.             Alert(RSRC_NUMBER_BASE + RESTART_RSRC, nil);
  328.         }
  329.         UseResFile(save_ref_num);
  330.     }
  331.     return(h);
  332. }
  333.  
  334. int open_prefs_file(prefs_file *pf)
  335. {
  336.     OSErr    er;
  337.     int        rn;
  338.     
  339.     er = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
  340.                         &(pf->vRefNum), &(pf->DirID));
  341.     if(er == 0) {
  342.         rn = HOpenResFile(pf->vRefNum, pf->DirID, PREFS_TITLE, fsRdWrPerm);
  343.         if(rn != -1) {
  344.             pf->RsrcRefNum = rn;
  345.             return(NO_ERROR);
  346.         }
  347.         return(OPEN_ERROR);
  348.     }
  349.     return(CAUTION_ERROR);
  350. }
  351.  
  352. void save_setting(init_data_hdl sysheap_data_hdl, prefs_file *pf_ptr)
  353. {
  354.     Handle            h;
  355.     init_data_hdl    work_data_hdl;
  356.     FInfo            f_info;
  357.     
  358.     HCreateResFile(pf_ptr->vRefNum, pf_ptr->DirID, PREFS_TITLE);
  359.     f_info.fdType = 'pref';
  360.     f_info.fdCreator = CREATOR;
  361.     f_info.fdFlags = 0;
  362.     HSetFInfo(pf_ptr->vRefNum, pf_ptr->DirID, PREFS_TITLE, &f_info);
  363.         //    You must call 'open_prefs_file' again.
  364.         //    Because HSetFInfo closes a file.
  365.     open_prefs_file(pf_ptr);
  366.  
  367.     work_data_hdl = (init_data_hdl)NewHandle(sizeof(init_data));
  368.     if(work_data_hdl) {
  369.         **work_data_hdl = **sysheap_data_hdl;
  370.         if(h = Get1Resource(SETTING_RSRC, RSRC_NUMBER_BASE + 1))
  371.             RmveResource(h);
  372.         AddResource((Handle)work_data_hdl, SETTING_RSRC, RSRC_NUMBER_BASE + 1, "\p");
  373.         ReleaseResource((Handle)work_data_hdl);
  374.         CloseResFile(CurResFile());
  375.     }
  376. }
  377.  
  378. void do_close(cdev_data_hdl ch)
  379. {
  380.     prefs_file    pf;
  381.     
  382.     open_prefs_file(&pf);
  383.     if(    ((**ch).temp_init_data.push_on == true) &&
  384.         ((**ch).temp_init_data.pop_on  == true) &&
  385.         (key1[0] == key2[0])    &&
  386.         (key1[1] == key2[1])    &&
  387.         (key1[2] == key2[2])    &&
  388.         (key1[3] == key2[3])    ) {
  389.             Alert(RSRC_NUMBER_BASE + SAME_RSRC, nil);
  390.             (**ch).temp_init_data.pop_on = false;
  391.     }
  392.     apply_setting(ch);
  393.     save_setting((init_data_hdl)ch, &pf);
  394.     DisposeHandle((Handle)ch);
  395. }
  396.  
  397.     //    other event routines ---------------------------
  398.  
  399. void do_hit(cdev_data_hdl ch, DialogPtr dp, short hit_item,
  400.                 EventRecord *evntp, short numItems)
  401. {
  402.     switch(hit_item) {
  403.         case k_drag_on:
  404.             (**ch).temp_init_data.drag_on = !(**ch).temp_init_data.drag_on;
  405.             setup_ditems(ch, dp, numItems);
  406.             apply_setting(ch);
  407.             break;
  408.         case k_grow_on:
  409.             (**ch).temp_init_data.grow_on = !(**ch).temp_init_data.grow_on;
  410.             setup_ditems(ch, dp, numItems);
  411.             apply_setting(ch);
  412.             break;
  413.         case k_push_on:
  414.             (**ch).temp_init_data.push_on = !(**ch).temp_init_data.push_on;
  415.             setup_ditems(ch, dp, numItems);
  416.             apply_setting(ch);
  417.             break;
  418.         case k_pop_on:
  419.             (**ch).temp_init_data.pop_on = !(**ch).temp_init_data.pop_on;
  420.             setup_ditems(ch, dp, numItems);
  421.             apply_setting(ch);
  422.             break;
  423.         case k_push_sound:
  424.             (**ch).temp_init_data.push_sound = !(**ch).temp_init_data.push_sound;
  425.             setup_ditems(ch, dp, numItems);
  426.             apply_setting(ch);
  427.             break;
  428.         case k_pop_sound:
  429.             (**ch).temp_init_data.pop_sound = !(**ch).temp_init_data.pop_sound;
  430.             setup_ditems(ch, dp, numItems);
  431.             apply_setting(ch);
  432.             break;
  433.         case k_show_icon:
  434.             (**ch).temp_init_data.show_init_icon = !(**ch).temp_init_data.show_init_icon;
  435.             setup_ditems(ch, dp, numItems);
  436.             apply_setting(ch);
  437.             break;
  438.         case k_push_ctrl:
  439.         case k_push_shift:
  440.         case k_push_option:
  441.         case k_push_command:
  442.             key1[hit_item - k_push_ctrl] = !key1[hit_item - k_push_ctrl];
  443.             check_key_combination(ch, hit_item - k_push_ctrl);
  444.             setup_ditems(ch, dp, numItems);
  445.             apply_setting(ch);
  446.             break;
  447.         case k_pop_ctrl:
  448.         case k_pop_shift:
  449.         case k_pop_option:
  450.         case k_pop_command:
  451.             key2[hit_item - k_pop_ctrl] = !key2[hit_item - k_pop_ctrl];
  452.             check_key_combination(ch, hit_item - k_pop_ctrl);
  453.             setup_ditems(ch, dp, numItems);
  454.             apply_setting(ch);
  455.             break;
  456.         case b_push_ctrl:
  457.         case b_push_shift:
  458.         case b_push_option:
  459.         case b_push_command:
  460.             key1[hit_item - b_push_ctrl] = !key1[hit_item - b_push_ctrl];
  461.             check_key_combination(ch, hit_item - b_push_ctrl);
  462.             setup_ditems(ch, dp, numItems);
  463.             apply_setting(ch);
  464.             break;
  465.         case b_pop_ctrl:
  466.         case b_pop_shift:
  467.         case b_pop_option:
  468.         case b_pop_command:
  469.             key2[hit_item - b_pop_ctrl] = !key2[hit_item - b_pop_ctrl];
  470.             check_key_combination(ch, hit_item - b_pop_ctrl);
  471.             setup_ditems(ch, dp, numItems);
  472.             apply_setting(ch);
  473.             break;
  474.         case k_no_marquee:
  475.             (**ch).temp_init_data.no_marquee = !(**ch).temp_init_data.no_marquee;
  476.             setup_ditems(ch, dp, numItems);
  477.             apply_setting(ch);
  478.             break;
  479.         case k_drag_ctrl:
  480.         case k_drag_shift:
  481.         case k_drag_option:
  482.         case k_drag_command:
  483.             key3[hit_item - k_drag_ctrl] = !key3[hit_item - k_drag_ctrl];
  484.             check_key_combination(ch, hit_item - k_drag_ctrl);
  485.             setup_ditems(ch, dp, numItems);
  486.             apply_setting(ch);
  487.             break;
  488.         case b_drag_ctrl:
  489.         case b_drag_shift:
  490.         case b_drag_option:
  491.         case b_drag_command:
  492.             key3[hit_item - b_drag_ctrl] = !key3[hit_item - b_drag_ctrl];
  493.             check_key_combination(ch, hit_item - b_drag_ctrl);
  494.             setup_ditems(ch, dp, numItems);
  495.             apply_setting(ch);
  496.             break;
  497.         case k_about:
  498.             about(RSRC_NUMBER_BASE + ABOUT_RSRC, nil);
  499.             break;
  500.     }
  501. }
  502.  
  503. void apply_setting(cdev_data_hdl cur_data_hdl)
  504. {
  505.     init_data_hdl    sysheap_data_hdl;
  506.     OSErr            err;
  507.     long            address;
  508.     
  509.     
  510.     err = Gestalt(CREATOR, &address);
  511.     if(err == NO_ERROR) {
  512.         sysheap_data_hdl = (init_data_hdl)address;
  513.         **sysheap_data_hdl = (**cur_data_hdl).temp_init_data;
  514.     }
  515. }
  516.  
  517. void setup_ditems(cdev_data_hdl ch, DialogPtr dp, short numItems)
  518. {
  519.     hilite_btn(ch, dp, numItems);
  520.  
  521.     set_check_btn(dp, k_drag_on        + numItems,  (**ch).temp_init_data.drag_on);
  522.     set_check_btn(dp, k_grow_on        + numItems,  (**ch).temp_init_data.grow_on);
  523.     set_check_btn(dp, k_push_on        + numItems,  (**ch).temp_init_data.push_on);
  524.     set_check_btn(dp, k_pop_on        + numItems,  (**ch).temp_init_data.pop_on);
  525.     set_check_btn(dp, k_push_sound    + numItems,  (**ch).temp_init_data.push_sound);
  526.     set_check_btn(dp, k_pop_sound    + numItems,  (**ch).temp_init_data.pop_sound);
  527.     set_check_btn(dp, k_push_ctrl    + numItems,  key1[0]);
  528.     set_check_btn(dp, k_push_shift    + numItems,  key1[1]);
  529.     set_check_btn(dp, k_push_option    + numItems,  key1[2]);
  530.     set_check_btn(dp, k_push_command+ numItems,  key1[3]);
  531.     set_check_btn(dp, k_pop_ctrl    + numItems,  key2[0]);
  532.     set_check_btn(dp, k_pop_shift    + numItems,  key2[1]);
  533.     set_check_btn(dp, k_pop_option    + numItems,  key2[2]);
  534.     set_check_btn(dp, k_pop_command    + numItems,  key2[3]);
  535.     set_check_btn(dp, k_show_icon    + numItems,  (**ch).temp_init_data.show_init_icon);
  536.     set_check_btn(dp, k_no_marquee    + numItems,  (**ch).temp_init_data.no_marquee);
  537.     set_check_btn(dp, k_drag_ctrl    + numItems,  key3[0]);
  538.     set_check_btn(dp, k_drag_shift    + numItems,  key3[1]);
  539.     set_check_btn(dp, k_drag_option    + numItems,  key3[2]);
  540.     set_check_btn(dp, k_drag_command+ numItems,  key3[3]);
  541.         //    These are not clever :-)
  542. }
  543.  
  544. void hilite_btn(cdev_data_hdl ch, DialogPtr dp, short numItems)
  545. {
  546.     short    item_type;
  547.     Handle    h;
  548.     Rect    r;
  549.     int        i, button;
  550.     
  551.     button = k_push_sound;
  552.     for( i = 0; i <= 4; i++) {
  553.         GetDItem(dp, numItems + button + i, &item_type, &h, &r);
  554.         HiliteControl((ControlHandle)h, (!(**ch).temp_init_data.push_on) * 255);
  555.     }
  556.     button = k_pop_sound;
  557.     for( i = 0; i <= 4; i++) {
  558.         GetDItem(dp, numItems + button + i, &item_type, &h, &r);
  559.         HiliteControl((ControlHandle)h, (!(**ch).temp_init_data.pop_on) * 255);
  560.     }
  561.     button = k_drag_ctrl;
  562.     for( i = 0; i <= 3; i++) {
  563.         GetDItem(dp, numItems + button + i, &item_type, &h, &r);
  564.         HiliteControl((ControlHandle)h,
  565.             (!( (**ch).temp_init_data.no_marquee * (**ch).temp_init_data.drag_on) ) * 255);
  566.     }
  567.     GetDItem(dp, numItems + k_no_marquee, &item_type, &h, &r);
  568.     HiliteControl((ControlHandle)h, (!(**ch).temp_init_data.drag_on) * 255);
  569.  
  570. void set_check_btn(DialogPtr dp, short item_num, Boolean is_on)
  571. {
  572.     short    item_type;
  573.     Handle    h;
  574.     Rect    r;
  575.     
  576.     GetDItem(dp, item_num, &item_type, &h, &r);
  577.     if(is_on)    SetCtlValue((ControlHandle)h, 1);
  578.     else        SetCtlValue((ControlHandle)h, 0);
  579. }
  580.  
  581. void check_key_combination(cdev_data_hdl ch, short key_num)
  582. {
  583.     if(    (key1[0] == false)    &&
  584.         (key1[1] == false)    &&
  585.         (key1[2] == false)    &&
  586.         (key1[3] == false)    ) {
  587.             key1[key_num] = true;
  588.     }
  589.     if(    (key2[0] == false)    &&
  590.         (key2[1] == false)    &&
  591.         (key2[2] == false)    &&
  592.         (key2[3] == false)    ) {
  593.             key2[key_num] = true;
  594.     }
  595. }
  596.  
  597.  
  598. void about(short id, void *p)
  599. {
  600.     GrafPtr            saved_port;
  601.     PenState        saved_pen_state;
  602.     WindowPtr        wp;
  603.     EventRecord        an_event;
  604.     KeyMap            my_keymap;
  605.     PicHandle        title_hdl;
  606.     Handle            icon_hdl;
  607.     Rect            r;
  608.     Str255            str;
  609.     int                i;
  610.     long            ticks, num_of_str;
  611.     short            fh, fv;
  612.     Boolean            exit_draw = false, color_icon, color_qd;
  613.     RGBColor        fore_color, back_color;
  614.     
  615.         //    I use GetNewCWindow, not GetDialog. Because StaticText of a dialog
  616.         //    displays 12pt of geneva, but I want to display text with 9pt.
  617.         //    If you don't want to use other than 12pt, use GetDialog. Fonts can be
  618.         //    changed with SetDAFont ( New Inside Macintosh: SetDialogFont ).
  619.     GetPort(&saved_port);
  620.     GetPenState(&saved_pen_state);
  621.     if(color_qd = TrapAvailable(_GetForeColor)) {
  622.         GetForeColor(&fore_color);
  623.         GetBackColor(&back_color);
  624.     }
  625.     SetRect(&r, 5, 5, 148, 35);
  626.     wp = GetNewCWindow(id, 0, (WindowPtr)-1);
  627.     ShowWindow(wp);
  628.     SetPort(wp);
  629.     title_hdl = GetPicture(RSRC_NUMBER_BASE);
  630.     DrawPicture(title_hdl, &r);
  631.     PenNormal();
  632.     TextSize(9);
  633.     GetIndString(str, RSRC_NUMBER_BASE + 1, 1);
  634.     StringToNum(str, &num_of_str);
  635.     for(i = 0; i <= num_of_str; i++) {
  636.         GetIndString(str, RSRC_NUMBER_BASE, i + 1);
  637.         MoveTo(20, 45 + i * 12);
  638.         DrawString(str); 
  639.     }
  640.     SetRect(&r, 280, 0, 328, 48);
  641.     color_icon = TrapAvailable(_GetCIcon);
  642.     if(color_icon) {
  643.         icon_hdl = (Handle)GetCIcon(RSRC_NUMBER_BASE + WINDOW_ICON);
  644.         PlotCIcon(&r, (CIconHandle)icon_hdl);
  645.     }
  646.     else {
  647.         icon_hdl = GetIcon(RSRC_NUMBER_BASE + WINDOW_ICON);
  648.         PlotIcon(&r, icon_hdl);
  649.     }
  650.     SetRect(&r, 1, 0, 49, 48);
  651.     PenPat(gray);
  652.     PenMode(patXor);
  653.     FrameRect(&r);
  654.     while(!exit_draw) {
  655.         FrameRect(&r);
  656.         OffsetRect(&r, 2, 0);
  657.         FrameRect(&r);
  658.         if(r.left == (280 - 47)) {
  659.             exit_draw = true;
  660.             if(color_icon)
  661.                 PlotCIcon(&r, (CIconHandle)icon_hdl);
  662.             else
  663.                 PlotIcon(&r, icon_hdl);
  664.         }
  665.     }
  666.     while(!(WaitNextEvent(mDownMask, &an_event, 100, 0)));
  667.     GetKeys(my_keymap);
  668.     if( (BitTst(my_keymap, COMMAND_KEY)) && (BitTst(my_keymap, OPTION_KEY))) {
  669.         EraseRect(&r);
  670.         OffsetRect(&r, 47, 0);
  671.         if(color_icon)
  672.             PlotCIcon(&r, (CIconHandle)icon_hdl);
  673.         else
  674.             PlotIcon(&r, icon_hdl);
  675.         OffsetRect(&r, 0, 48);
  676.         if(color_icon)
  677.             PlotCIcon(&r, (CIconHandle)icon_hdl);
  678.         else
  679.             PlotIcon(&r, icon_hdl);
  680.         SysBeep(1);
  681.         while(!(WaitNextEvent(mDownMask, &an_event, 100, 0)));
  682.     }
  683.     if(color_icon)
  684.         DisposeCIcon((CIconHandle)icon_hdl);
  685.     else
  686.         DisposeHandle(icon_hdl);
  687.     DisposeWindow(wp);
  688.     SetPort(saved_port);
  689.     SetPenState(&saved_pen_state);
  690.     if(color_qd) {
  691.         RGBForeColor(&fore_color);
  692.         RGBBackColor(&back_color);
  693.     }
  694.     FlushEvents(everyEvent, 0);
  695. }
  696.